from datetime import datetime

import pytz
from django.utils import timezone
from dateutil.relativedelta import relativedelta


tzinfo = datetime.now().astimezone(pytz.timezone('Asia/Shanghai')).tzinfo


def gen_month_day1():
    dt = timezone.now().astimezone(tzinfo)
    return dt.replace(day=1, hour=0, minute=0, second=0, microsecond=0)


def gen_month_range():
    end_time = gen_month_day1()
    begin_time = end_time - relativedelta(months=1)
    return begin_time, end_time


def astimezone2cst(dt:datetime):
    return dt.astimezone(tzinfo)
